import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home'
import store from '@/store'
import permission from './permission'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/course',
    name: 'course',
    component: () => import('@/views/Course'),
    //标识，是否需要登陆
    meta: {
      needLogin: true
    }
  },
  {
    path: '/profile',
    name: 'profile',
    component: () => import('@/views/Profile')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login')
  },


]





const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


//1.判断是否登陆过 =>如果登陆过...
//                =>如果没有登陆过 判断用户是否需要登陆
Object.values(permission).forEach(hook => {
  router.beforeEach(hook.bind(router))
})


export default router
